package io.wit.modules.wit.controller;

import io.wit.common.utils.PageUtils;
import io.wit.common.utils.Querys;
import io.wit.common.utils.R;
import io.wit.modules.wit.entity.IntegralEntity;
import io.wit.modules.wit.service.IntegralService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


/**
 * 积分管理
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-01-02 14:45:16
 */
@RestController
@RequestMapping("integral")
public class IntegralController {
	@Autowired
	private IntegralService integralService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("integral:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
		Querys query = new Querys(params);

		List<IntegralEntity> integralList = integralService.queryList(query);
		int total = integralService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(integralList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{dataId}")
	@RequiresPermissions("integral:info")
	public R info(@PathVariable("dataId") Long dataId){
		IntegralEntity integral = integralService.queryObject(dataId);
		
		return R.ok().put("integral", integral);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("integral:save")
	public R save(@RequestBody IntegralEntity integral){
		integralService.save(integral);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("integral:update")
	public R update(@RequestBody IntegralEntity integral){
		integralService.update(integral);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("integral:delete")
	public R delete(@RequestBody Long[] dataIds){
		integralService.deleteBatch(dataIds);
		
		return R.ok();
	}
	
}
